Skip to content

Navigation: Reduce include dependencies with forward declares#117557

Open
akien-mga wants to merge 1 commit intogodotengine:masterfrom
akien-mga:navigation-includes-cleanup
Open

Navigation: Reduce include dependencies with forward declares#117557
akien-mga wants to merge 1 commit intogodotengine:masterfrom
akien-mga:navigation-includes-cleanup

Conversation

@akien-mga
Copy link
Copy Markdown
Member

I checked manually all navigation_* and nav_* headers to see what includes could be removed or replaced by forward declares, to reduce incremental recompilation time.

@akien-mga akien-mga added this to the 4.x milestone Mar 18, 2026
@akien-mga akien-mga requested review from a team as code owners March 18, 2026 11:48
@akien-mga akien-mga requested review from a team as code owners March 18, 2026 11:48
@akien-mga akien-mga requested review from a team as code owners March 18, 2026 11:48
@akien-mga akien-mga removed request for a team March 18, 2026 11:48
Comment on lines -39 to +41
#include "scene/resources/shader_include.h"

class ShaderInclude;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the only non-navigation change in the PR. I initially set out to minimize includes of scene headers in servers headers, which is how I fell into this navigation rabbit hole.

@akien-mga akien-mga force-pushed the navigation-includes-cleanup branch 2 times, most recently from f3d4408 to af3d3ea Compare March 18, 2026 12:15
Comment on lines +39 to +43
class NavAgent2D;
class NavLink2D;
class NavMap2D;
class NavObstacle2D;
class NavRegion2D;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like MSVC doesn't like the use of forward declared types in RID_Owner, unlike GCC and Clang:

Error: .\core/templates/rid_owner.h(431): error C2027: use of undefined type 'NavObstacle2D'
D:\a\godot\godot\modules\navigation_2d\2d/godot_navigation_server_2d.h(42): note: see declaration of 'NavObstacle2D'
.\core/templates/rid_owner.h(431): note: the template instantiation context (the oldest one first) is
D:\a\godot\godot\modules\navigation_2d\2d/godot_navigation_server_2d.h(81): note: see reference to class template instantiation 'RID_Owner<NavObstacle2D,false>' being compiled
.\core/templates/rid_owner.h(518): note: see reference to class template instantiation 'RID_Alloc<T,false>' being compiled
        with
        [
            T=NavObstacle2D
        ]
.\core/templates/rid_owner.h(424): note: while compiling class template member function 'RID_Alloc<T,false>::~RID_Alloc(void)'
        with
        [
            T=NavObstacle2D
        ]
Error: .\core/templates/rid_owner.h(94): error C2079: 'RID_Alloc<T,false>::Chunk::data' uses undefined class 'NavObstacle2D'
        with
        [
            T=NavObstacle2D
        ]
.\core/templates/rid_owner.h(94): note: the template instantiation context (the oldest one first) is
.\core/templates/rid_owner.h(93): note: while compiling class 'RID_Alloc<T,false>::Chunk'
        with
        [
            T=NavObstacle2D
        ]
Error: .\core/templates/rid_owner.h(439): error C2325: 'T': unexpected type to the right of '.~': expected '<error type>'
        with
        [
            T=NavObstacle2D
        ]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted those forward declares since MSVC doesn't like them.
godot_navigation_server_*.h is only included in register_types.cpp anyway so forward declares here weren't particularly beneficial.

@akien-mga akien-mga force-pushed the navigation-includes-cleanup branch from af3d3ea to 496ee51 Compare March 18, 2026 13:03
Copy link
Copy Markdown
Contributor

@StarryWorm StarryWorm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Total includes project-wide go from 187973 to 187461 with this PR1, so -512 or -0.27%. That's actually a kind of huge improvement for such a small change.

LGTM!

1 Data obtained by cherry-picking the commit to a new branch off of master as the PR branch is a bit behind. Numbers only reflect total includes by *.cpp files.

@akien-mga akien-mga force-pushed the navigation-includes-cleanup branch from 496ee51 to 7b19202 Compare March 20, 2026 12:40
@akien-mga akien-mga force-pushed the navigation-includes-cleanup branch from 7b19202 to a165500 Compare March 20, 2026 12:48
@akien-mga akien-mga requested a review from a team as a code owner March 20, 2026 12:48
#include "core/object/class_db.h"
#include "scene/3d/skeleton_3d.h"
#include "scene/main/scene_tree.h"
#include "servers/rendering/rendering_server.h"
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may have been missing in the master branch too, I found it by compiling this PR with target=template_release disable_navigation_2d=yes disable_navigation_3d=yes.

@Repiteo Repiteo modified the milestones: 4.x, 4.8 Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants